package com.leo;

import javafx.beans.binding.Bindings;
import javafx.beans.binding.StringBinding;
import javafx.beans.binding.StringExpression;
import javafx.beans.property.SimpleIntegerProperty;

import java.util.Locale;
import java.util.concurrent.Callable;

/**
 * @ClassName BindingsDemo
 * @Description
 * @Author wangss
 * @date 2020.06.01 20:29
 * @Version 1.0
 */
public class BindingsDemo {

    public static void main(String[] args) {
        SimpleIntegerProperty property = new SimpleIntegerProperty(10);

        StringExpression sexp = Bindings.concat("value = ", property.asString(Locale.getDefault(), "%s"));

        System.out.println(sexp.get());

        StringExpression sexp2 = Bindings.format("value = %s", property);

        System.out.println(sexp2.get());

        SimpleIntegerProperty a = new SimpleIntegerProperty(11);
        SimpleIntegerProperty b = new SimpleIntegerProperty(12);

        StringBinding sb = Bindings.createStringBinding(new Callable<String>() {
            @Override
            public String call() throws Exception {

                if (a.get() == 11) {
                    return "A";
                } else if (a.get() == 12) {
                    return "B";
                }
                return "hello";
            }
        }, a);

        System.out.println("a = " + a.get());
        System.out.println("sb = " + sb.get());
    }
}
